#include"all.hpp"
#include"Log.hpp"

using namespace std;

//管理管道文件
int main()
{

    Init init;
    Log log(Onefile);

    //打开信道
    int fd = open(FIFO_FILE, O_RDONLY);
    if(fd < 0)
    {
        log(Fatal, "error string: %s, error code: %d", strerror(errno), errno);
        exit(FIFO_OPEN_ERR);
    }
    log(Info, "server open file done, error string: %s, error code: %d", strerror(errno), errno);
    //client打开后才打印，说明open阻塞了
    //开始通信
    while(true)
    {
        char buffer[1024];
        int x = read(fd, buffer,sizeof(buffer));
        if(x > 0)
        {
            buffer[x] = 0;
            cout<<"client :"<<buffer<<endl;
        }
        else if(x == 0) 
        {
            log(Debug, "client quit, error string: %s, error code: %d", strerror(errno), errno);
            break;
        }
        else break;
    }


    close(fd);


    return 0;
}

// int main()
// {
//     cout<<sum(1, 13)<<endl;
//     cout<<sum(2, 4, 4)<<endl;
//     cout<<sum(3, 5, 6, 7)<<endl;
//     return 0;
// }

// int main()
// {
//     Logmessage(Info, "linux for world %d",1);
//     return 0;
// }